package com.bocek.chakmapoint.model;

import static org.junit.Assert.*;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.geom.Line2D;


import org.junit.*;

/**
 * A rectangle slide item.
 * 
 * @author Emin Bugra Saral
 * @version 1.2
 */
public class CRectangleTest {
	CRectangle test;
	Dimension frame;
	
	@Before
	public void setUp(){
		test = new CRectangle();
		test.setBounds(10, 24, 500, 600);
		test.repOK();
		frame = new Dimension(900,800);
	}
	
	@Test
	public void test_setAndGetSelection(){
		test.setSelection(Selection.POINT);
		test.repOK();
		assertEquals(test.getSelection(), Selection.POINT);
		test.setSelection(Selection.NONE);
		test.repOK();
		assertEquals(test.getSelection(), Selection.NONE);
	}
	
	@Test public void test_setAndGetThickness(){
		test.setThickness(10);
		test.repOK();
		assertEquals(test.getThickness(), 10);
		test.setThickness(1);
		test.repOK();
		assertEquals(test.getThickness(), 1);
	}
	
	@Test
	public void test_getName(){
		assertEquals(test.getName(), "Rectangle");
	}
	
	@Test
	public void test_isPointInside(){
		Point p = new Point(10, 25);
		assertTrue(test.isPointInside(p));
		
		p.setLocation(10, 23);
		assertFalse(test.isPointInside(p));
	}
	
	@Test
	public void test_select(){
		// BLACK BOX TEST OF SELECT
		Point p = new Point(2, 4);
		test.select(p);
		assertEquals(test.getSelection(), Selection.NONE);
		test.deselect();
		test.repOK();
		
		p.setLocation(500,300);
		test.select(p);
		test.repOK();
		assertEquals(test.getSelection(), Selection.ALL);
	}
	
	@Test
	public void test_deselect(){
		test.select(new Point(500,300));
		assertTrue(test.isSelected());
		test.deselect();
		test.repOK();
		assertFalse(test.isSelected());
	}
	
	@Test
	public void test_isSelected(){
		// BLACK BOX TEST OF SELECT
		assertFalse(test.isSelected());
		Point p = new Point(16, 60);
		test.select(p);
		test.repOK();
		assertTrue(test.isSelected());
	}
	
	@Test
	public void test_isOutsideFrame(){
		assertFalse(test.isOutsideFrame(frame));
		test.setBounds(10, 10, 900, 700);
		test.repOK();
		assertTrue(test.isOutsideFrame(frame));	
	}
	
	@Test
	public void test_setAndGetColor(){
		test.setColor(Color.red);
		test.repOK();
		assertEquals(test.getColor(), Color.red);
	}
}
